#include <stddef.h>
#include <stdint.h>

#include "../uch.h"

#include "munit/munit.h"

static MunitResult
test_uch(const MunitParameter params[], void *data)
{
	Uch ch;
	Ch_len len;
	const char *str = "😊a¢";

	munit_assert_int(ch_len_f("a"), ==, 1);
	munit_assert_int(ch_len_f("¢"), ==, 2);
	munit_assert_int(ch_len_f("€"), ==, 3);
	munit_assert_int(ch_len_f("😊"), ==, 4);

	ch = uch("a", &len);
	munit_assert_int(ch_len(ch), ==, len);
	munit_assert_int(len, ==, 1);

	ch = uch("¢", &len);
	munit_assert_int(ch_len(ch), ==, len);
	munit_assert_int(len, ==, 2);

	ch = uch("€", &len);
	munit_assert_int(ch_len(ch), ==, len);
	munit_assert_int(len, ==, 3);

	ch = uch("😊", &len);
	munit_assert_int(ch_len(ch), ==, len);
	munit_assert_int(len, ==, 4);

	str += ch_len_f(str);
	str += ch_len_f(str);
	str += ch_len_f(str);


	munit_assert_int((len = ch_len_b(str)), ==, 2);
	str -= len;
	munit_assert_int((len = ch_len_b(str)), ==, 1);
	str -= len;
	munit_assert_int((len = ch_len_b(str)), ==, 4);
	return MUNIT_OK;
}

static MunitTest test_suite_tests[] = {
	{ (char *) "/uch", test_uch,
	  NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
	{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};

static const MunitSuite test_suite = {
	(char*) "uch",
	test_suite_tests,
	NULL,
	1,
	MUNIT_SUITE_OPTION_NONE
};

int
main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)])
{
	return munit_suite_main(&test_suite, NULL, argc, argv);
}
